#ifndef __AUDIO_TRANSCODE_HPP__
#define __AUDIO_TRANSCODE_HPP__

#include <functional>

extern "C" {
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
    #include <libswresample/swresample.h>
}

//opus to aac
class aTranscode {
public:
    typedef std::function<int(uint8_t* data, size_t len, const int64_t& pts)> Output;
private:
    AVPacket* depkt_ = nullptr;
    AVPacket* enpkt_ = nullptr;
    AVFrame* framein_ = nullptr;
    AVFrame* frameout_ = nullptr;
    AVCodecContext* dectx_ = nullptr;
    AVCodecContext* enctx_ = nullptr;
    SwrContext *swrctx_ = nullptr;

public:
    ~aTranscode();

    int init(int src_sample_rate, int src_channel, int src_bit_rate, int dst_sample_rate, int dst_channel, int dst_bit_rate);
    int opened();
    int transcode(uint8_t* data, size_t length, const int64_t& pts, const int64_t& dts, const Output& func);

private:
    int encode(AVFrame* frame, const Output& func);
    int __transcode(AVPacket* pkt, const Output& func);
};

#endif  //__AUDIO_TRANSCODE_HPP